package com.ctshk.sapp.order.custom.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.exception.BusinessException;
import com.ctshk.common.model.PageResponse;
import com.ctshk.rpc.order.custom.dto.order.ApprovalQuitInfoDTO;
import com.ctshk.rpc.order.custom.dto.order.CustomOrderTouristQuitListDTO;
import com.ctshk.rpc.order.custom.dto.order.CustomOrderTouristQuitNoticeDetailDTO;
import com.ctshk.rpc.order.custom.req.order.*;
import com.ctshk.rpc.order.custom.service.ICustomizedOrderTouristQuitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.ctshk.common.web.support.BaseController;

import javax.validation.Valid;

/**
 * <p>
 * 游客退团 前端控制器
 * </p>
 *
 * @author 叶冠峰
 * @since 2021-02-22
 */
@Api(value="旅客退团", tags="旅客退团")
@RestController
@Slf4j
@RequestMapping("/customized-order-tourist-quit")
public class CustomizedOrderTouristQuitController extends BaseController {

    @DubboReference
    private ICustomizedOrderTouristQuitService orderTouristQuitService;


    @ApiOperation(value = "列表", notes = "游客退团列表（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "游客退团列表", operDesc = "游客退团列表")
    @PostMapping("/list")
    public Result<PageResponse<CustomOrderTouristQuitListDTO>> list(@RequestBody @Valid CustomOrderTouristQuitListReq req) {
        try {
            req.setUserId(getCurrentUser(getRequest()).getId());
            return Result.success(orderTouristQuitService.list(req));
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }


    @ApiOperation(value = "申請退團", notes = "申請退團（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "退團管理-申請退團", operDesc = "退團管理-申請退團")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid CustomOrderTouristQuitAddReq req) {
        try {
            req.setUserId(getCurrentUser(getRequest()).getId());
            return orderTouristQuitService.add(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }


    @ApiOperation(value = "退團通知書", notes = "退團通知書（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "退團管理-退團通知書", operDesc = "退團管理-退團通知書")
    @PostMapping("/notice")
    public Result<CustomOrderTouristQuitNoticeDetailDTO> notice(@RequestBody @Valid CustomOrderTouristQuitIdReq req) {
        try {
            req.setUserId(getCurrentUser(getRequest()).getId());
            return orderTouristQuitService.notice(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }


    @ApiOperation(value = "操作退款", notes = "操作退款（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "退團管理-操作退款", operDesc = "退團管理-操作退款")
    @PostMapping("/confirm")
    public Result confirm(@RequestBody @Valid CustomOrderTouristQuitConfirmReq req) {
        try {
            req.setUserId(getCurrentUser(getRequest()).getId());
            return orderTouristQuitService.confirm(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }


    @ApiOperation(value = "撤回", notes = "撤回（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "退團管理-操作退款", operDesc = "退團管理-操作退款")
    @PostMapping("/withdraw")
    public Result withdraw(@RequestBody @Valid CustomOrderTouristQuitIdReq req) {
        try {
            req.setUserId(getCurrentUser(getRequest()).getId());
            return orderTouristQuitService.withdraw(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }


    @ApiOperation(value = "添加计算", notes = "添加计算（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "退團管理-申請退團", operDesc = "退團管理-申請退團")
    @PostMapping("/add/calculation")
    public Result addCalculation(@RequestBody @Valid CustomOrderTouristQuitAddCalculationReq req) {
        try {
            req.setUserId(getCurrentUser(getRequest()).getId());
            return orderTouristQuitService.addCalculation(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "审批", notes = "审批")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "退團管理-审批", operDesc = "退團管理-审批")
    @PostMapping("/approval")
    public Result approval(@RequestBody @Valid ApprovalQuitReq req) {
        try {
            req.setUserId(getCurrentUser(getRequest()).getId());
            return orderTouristQuitService.approval(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "审批中心-退团信息", notes = "审批中心-退团信息")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "审批中心-退团信息", operDesc = "审批中心-退团信息")
    @PostMapping("/approval-quit-info")
    public Result<ApprovalQuitInfoDTO> approvalQuitInfo(@RequestBody @Valid ApprovalIdReq req) {
        try {
            return orderTouristQuitService.approvalQuitInfo(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

}
